﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using FOModels.DepositSaving;
using DataAccess;
using DataAccess.DepositSaving;
using System.Net;
namespace Bussiness.DepositSaving
{
    public class DepositSavingBLL
    {
        private DepositSavingDAL dal;
        public DepositSavingBLL()
        {
            dal = new DepositSavingDAL();
        }
        public int UpdateStatus(DepositSavingApplyModels card)
        {
            if (dal.UpdateStatus(card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteDepositSavingApply(int SavingDepositApplyID)
        {
            if (dal.DeleteDepositSavingApply(SavingDepositApplyID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DepositSavingApply(int DepositSavingID, DepositSavingApplyModels card)
        {
            if (dal.DepositSavingApply(DepositSavingID, card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public DepositSavingApplyModels getcontractbyid(int cardapplyid)
        {

            DepositSavingApplyModels fur = new DepositSavingApplyModels();
            DataTable tb = dal.getcontractbyid(cardapplyid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingApplyModels();
                    fur.DepositSavingApplyID = int.Parse(row[0].ToString());
                    fur.DepositSavingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.DepositSavingName = row[10].ToString();
                    fur.CompanyImg = row[19].ToString();
                    fur.CompanyName = row[26].ToString();
                    fur.StatusName = row[17].ToString();
                }
            }
            return fur;
        }
        public List<DepositSavingApplyModels> getcontract()
        {
            List<DepositSavingApplyModels> list = new List<DepositSavingApplyModels>();
            DepositSavingApplyModels fur;
            DataTable tb = dal.getcontract();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingApplyModels();
                    fur.DepositSavingApplyID = int.Parse(row[0].ToString());
                    fur.DepositSavingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.DepositSavingName = row[10].ToString();
                    fur.CompanyImg = row[19].ToString();
                    fur.CompanyName = row[26].ToString();
                    fur.StatusName = row[17].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingApplyModels> getcontractbystatus(int statusid)
        {
            List<DepositSavingApplyModels> list = new List<DepositSavingApplyModels>();
            DepositSavingApplyModels fur;
            DataTable tb = dal.getcontractbystatus(statusid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingApplyModels();
                    fur.DepositSavingApplyID = int.Parse(row[0].ToString());
                    fur.DepositSavingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.DepositSavingName = row[10].ToString();
                    fur.CompanyImg = row[19].ToString();
                    fur.CompanyName = row[26].ToString();
                    fur.StatusName = row[17].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingModels> getTermSavingDefaultByProvider(int CompanyID, int langid)
        {
            List<DepositSavingModels> list = new List<DepositSavingModels>();
            DepositSavingModels fur;
            DataTable tb = dal.getTermSavingDefaultByProvider(CompanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingModels> getDepositSaving(int cateid, string balance, int month, int langid)
        {
            List<DepositSavingModels> list = new List<DepositSavingModels>();
            DepositSavingModels fur;
            DataTable tb = dal.getDepositSavingList(cateid, balance, month, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingModels> getDepositSavingListByProvider(int cateid, string balance, int month, int ConpanyID, int langid)
        {
            List<DepositSavingModels> list = new List<DepositSavingModels>();
            DepositSavingModels fur;
            DataTable tb = dal.getDepositSavingListByProvider(cateid, balance, month, ConpanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingModels> getTermSavingDefault(int langid)
        {
            List<DepositSavingModels> list = new List<DepositSavingModels>();
            DepositSavingModels fur;
            DataTable tb = dal.getTermSavingDefault(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingModels> getdepositsavingrelati(int CompanyID, int DepositSavingID, int langid)
        {
            List<DepositSavingModels> list = new List<DepositSavingModels>();
            DepositSavingModels fur;
            DataTable tb = dal.getdepositsavingrelati(CompanyID, DepositSavingID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingCateModels> getDepositSavingCate(int langid)
        {
            List<DepositSavingCateModels> list = new List<DepositSavingCateModels>();
            DepositSavingCateModels fur;
            DataTable tb = dal.getDepositSavingCategory(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCateModels();
                    fur.SavingDepositCategoryID = int.Parse(row[0].ToString());
                    fur.SavingDepositCategoryName = row[4].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public DepositSavingModels getDepositSavingByID(int SavingDepositID, int langid)
        {
            DepositSavingModels fur = new DepositSavingModels();
            DataTable tb = dal.getDepositSavingByID(SavingDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {

                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                }
            }
            return fur;
        }
        public DepositSavingModels getDepositSavingByIDManager(int SavingDepositID, int langid)
        {
            DepositSavingModels fur = new DepositSavingModels();
            DataTable tb = dal.getDepositSavingByIDManager(SavingDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {

                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                }
            }
            return fur;
        }
        public DepositSavingModels gettop1termsaving()
        {
            DepositSavingModels fur = new DepositSavingModels();
            DataTable tb = dal.gettop1termsaving();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                }
            }
            return fur;
        }
        public List<DepositSavingModels> getall(int langid)
        {
            List<DepositSavingModels> list = new List<DepositSavingModels>();
            DepositSavingModels fur;
            DataTable tb = dal.getall(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {

                    fur = new DepositSavingModels();
                    fur.DepositSavingID = int.Parse(row[0].ToString());
                    fur.DepositSavingName = row[9].ToString();
                    fur.MinimumBalance = row[2].ToString();
                    fur.CompanyID = int.Parse(row[3].ToString());
                    fur.MaximumBalance = row[4].ToString();
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.FlagImage = row[27].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public int UpdateDepositSaving(DepositSavingModels models, int langid)
        {
            if (dal.UpdateDepositSaving(models) > 0 && dal.UpdateDepositSavingLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertDepositSaving(DepositSavingModels models)
        {
            if (dal.InsertDepositSaving(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertDepositSavingLang(DepositSavingModels models, int langid)
        {
            if (dal.InsertDepositSavingLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteDepositSaving(int DepositSavingID)
        {
            if (dal.DeleteDepositSavingLang(DepositSavingID) > 0 && dal.DeleteDepositSaving(DepositSavingID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }


    }
}
